from utils.Logger import Logger
from services.DeepSeekService import DeepSeekService
from services.ZhipuService import ZhipuService
from services.QwenService import QwenService
from config import Config

class AIServiceFactory:
    """AI服务工厂类"""
    
    @staticmethod
    def create_service(config: Config, loop=None):
        """根据配置创建对应的AI服务实例"""
        logger = Logger(__name__)
        try:
            provider = config.get_current_provider()
            logger.debug(f"Creating AI service for provider: {provider}")
            
            if provider == "deepseek":
                logger.info("Initializing DeepSeek service")
                return DeepSeekService(config.get_api_key("deepseek"), loop)
            elif provider == "zhipu":
                logger.info("Initializing Zhipu service")
                return ZhipuService(config.get_api_key("zhipu"), loop)
            elif provider == "qwen":
                logger.info("Initializing Qwen service")
                return QwenService(config.get_api_key("qwen"), loop)
            else:
                error_msg = f"Unsupported AI provider: {provider}"
                logger.error(error_msg)
                raise ValueError(error_msg)
                
        except Exception as e:
            logger.critical(f"Failed to create AI service: {str(e)}", exc_info=True)
            raise
